<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
    <script>
      var myMixin = {
        created: function () {
          this.hello();
        },
        methods: {
          hello: function () {
            console.log("hello form mixin");
          },
        },
      };

      var Component = Vue.extend({
        mixins: [myMixin],
      });

      var component = new Component();

      var mixin = {
        data: function () {
          return {
            message: "hello",
            foo: "abc",
          };
        },
      };

      new Vue({
        mixins: [mixin],
        data: function () {
          return {
            message: "goodbye",
            bar: "def",
          };
        },
        created: function () {
          console.log(this.$data);
        },
      });

      var mixin2 = {
        created: function () {
          console.log("从混入的创建钩子函数");
        },
      };

      new Vue({
        mixins: [mixin2],
        created: function () {
          console.log("组件钩子被调用");
        },
      });

      var mixin3 = {
        methods: {
          foo: function () {
            console.log("foo");
          },
          conficting: function () {
            console.log("form mixin");
          },
        },
      };
      var vm = new Vue({
        mixins: [mixin3],
        methods: {
          bar: function () {
            console.log("bar");
          },
          conficting: function () {
            console.log("from self");
          },
        },
      });
    </script>
  </body>
</html>
